/*
Package make
@Author   : Uyynot
@Email    : uyynot@qq.com
@Time     : 2024/4/12 16:54
@File     : make_cmd.go
@Project  : gohub
@Desc     :
*/
package make

import (
	"fmt"
	"github.com/spf13/cobra"
	"gohub/pkg/console"
)

var CmdMakeCMD = &cobra.Command{
	Use:   "cmd",
	Short: "Create a command, should be snack_case, exmaple:make cmd backup_database",
	Run:   runMakeCMD,
	Args:  cobra.MinimumNArgs(1), //仅允许切必须传1个参数
}

func runMakeCMD(cmd *cobra.Command, args []string) {
	//格式化模型名称，返回一个Model对象
	model := makeModelFormString(args[0])

	//拼接目标文件路径
	filePath := fmt.Sprintf("app/cmd/%s.go", model.PackageName)

	//从模板中创建文件(做好变量替换)
	createFileFromStub(filePath, "cmd", model)

	//友好提示
	console.Success("command name:" + model.PackageName)
	console.Success("command variable name: cmd.Cmd" + model.StructName)
	console.Warning("please edit main.go's app.Commands slice to register command")
}
